package com.ucas.kafka;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import com.ucas.protobuf.Lns;
import com.ucas.protobuf.Lns.EuEntity;
import com.ucas.protobuf.Lns.ReplayResponse;
import com.ucas.protobuf.TCPMsgEntity.CmdEntity;
import com.ucas.protobuf.TCPMsgEntity.TcpCmdExecState;


@Component
@SuppressWarnings({"unchecked","rawtypes"})
public class KafkaSender {
	@Autowired
	KafkaTemplate kafkaTemplate;
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public void sendMessage() {
		TcpCmdExecState.Builder tces = TcpCmdExecState.newBuilder();
		tces.setLen(10);
		tces.setSatid("123456789");
		tces.setData("1234567890");
		CmdEntity.Builder ce = CmdEntity.newBuilder();
		ce.setCmdid("123");
		tces.setCmd(ce);
		byte[] tcesbyte = tces.build().toByteArray();
		kafkaTemplate.send("vela-tcpmsg",new String(tcesbyte));
		
		
		ReplayResponse.Builder rr = ReplayResponse.newBuilder();
		rr.setEor(true);
		rr.setCid(3);
		EuEntity.Builder ee1 = EuEntity.newBuilder();
//		ee1.setRaw(System.currentTimeMillis());
//		ee1.setTmid(262281);
		ee1.setDisplay("帧计数");
		ee1.setVoltage(10L);
		rr.addEu(ee1);
		byte[] engbcbyte = rr.build().toByteArray();
		kafkaTemplate.send("engbc",new String(engbcbyte));
	}
}
